package com.plian.system.config;

import com.google.common.base.Predicates;
import com.plian.system.enumeratea.ModelEnum;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @description:
 * @author: gangan
 * @create: 2020-12-21 15:25
 */
@Configuration
@EnableSwagger2
@Profile({"dev"})
public class SwaggerConfig {

    @Bean
    public Docket createDjApi(){
        return new Docket(DocumentationType.SWAGGER_2).groupName(ModelEnum.DJ.getGroupName()).apiInfo(apiInfo())
                .select()
                .apis(Predicates.or(
                        RequestHandlerSelectors.basePackage(ModelEnum.DJ.getPackagePath())
                ))
                .paths(PathSelectors.any()).build();
    }
    @Bean
    public Docket createDpApi(){
        return new Docket(DocumentationType.SWAGGER_2).groupName(ModelEnum.DP.getGroupName()).apiInfo(apiInfo())
                .select()
                .apis(Predicates.or(
                        RequestHandlerSelectors.basePackage(ModelEnum.DP.getPackagePath())
                ))
                .paths(PathSelectors.any()).build();
    }

    @Bean
    public Docket createFrApi(){
        return new Docket(DocumentationType.SWAGGER_2).groupName(ModelEnum.FR.getGroupName()).apiInfo(apiInfo())
                .select()
                .apis(Predicates.or(
                        RequestHandlerSelectors.basePackage(ModelEnum.FR.getPackagePath())
                ))
                .paths(PathSelectors.any()).build();
    }

    @Bean
    public Docket createHrApi(){
        return new Docket(DocumentationType.SWAGGER_2).groupName(ModelEnum.HR.getGroupName()).apiInfo(apiInfo())
                .select()
                .apis(Predicates.or(
                        RequestHandlerSelectors.basePackage(ModelEnum.HR.getPackagePath())
                ))
                .paths(PathSelectors.any()).build();
    }

    @Bean
    public Docket createImApi(){
        return new Docket(DocumentationType.SWAGGER_2).groupName(ModelEnum.IM.getGroupName()).apiInfo(apiInfo())
                .select()
                .apis(Predicates.or(
                        RequestHandlerSelectors.basePackage(ModelEnum.IM.getPackagePath())
                ))
                .paths(PathSelectors.any()).build();
    }

    @Bean
    public Docket createLgApi(){
        return new Docket(DocumentationType.SWAGGER_2).groupName(ModelEnum.LG.getGroupName()).apiInfo(apiInfo())
                .select()
                .apis(Predicates.or(
                        RequestHandlerSelectors.basePackage(ModelEnum.LG.getPackagePath())
                ))
                .paths(PathSelectors.any()).build();
    }

    @Bean
    public Docket createMsApi(){
        return new Docket(DocumentationType.SWAGGER_2).groupName(ModelEnum.MS.getGroupName()).apiInfo(apiInfo())
                .select()
                .apis(Predicates.or(
                        RequestHandlerSelectors.basePackage(ModelEnum.MS.getPackagePath())
                ))
                .paths(PathSelectors.any()).build();
    }
    @Bean
    public Docket createMtApi(){
        return new Docket(DocumentationType.SWAGGER_2).groupName(ModelEnum.MT.getGroupName()).apiInfo(apiInfo())
                .select()
                .apis(Predicates.or(
                        RequestHandlerSelectors.basePackage(ModelEnum.MT.getPackagePath())
                ))
                .paths(PathSelectors.any()).build();
    }


    @Bean
    public Docket createOmApi(){
        return new Docket(DocumentationType.SWAGGER_2).groupName(ModelEnum.OM.getGroupName()).apiInfo(apiInfo())
                .select()
                .apis(Predicates.or(
                        RequestHandlerSelectors.basePackage(ModelEnum.OM.getPackagePath())
                ))
                .paths(PathSelectors.any()).build();
    }

    @Bean
    public Docket createPfApi(){
        return new Docket(DocumentationType.SWAGGER_2).groupName(ModelEnum.PF.getGroupName()).apiInfo(apiInfo())
                .select()
                .apis(Predicates.or(
                        RequestHandlerSelectors.basePackage(ModelEnum.PF.getPackagePath())
                ))
                .paths(PathSelectors.any()).build();
    }

    @Bean
    public Docket createPmApi(){
        return new Docket(DocumentationType.SWAGGER_2).groupName(ModelEnum.PM.getGroupName()).apiInfo(apiInfo())
                .select()
                .apis(Predicates.or(
                        RequestHandlerSelectors.basePackage(ModelEnum.PM.getPackagePath())
                ))
                .paths(PathSelectors.any()).build();
    }

    @Bean
    public Docket createQgApi(){
        return new Docket(DocumentationType.SWAGGER_2).groupName(ModelEnum.QG.getGroupName()).apiInfo(apiInfo())
                .select()
                .apis(Predicates.or(
                        RequestHandlerSelectors.basePackage(ModelEnum.QG.getPackagePath())
                ))
                .paths(PathSelectors.any()).build();
    }

    @Bean
    public Docket createSysApi(){
        return new Docket(DocumentationType.SWAGGER_2).groupName(ModelEnum.SYS.getGroupName()).apiInfo(apiInfo())
                .select()
                .apis(Predicates.or(
                        RequestHandlerSelectors.basePackage(ModelEnum.SYS.getPackagePath())
                ))
                .paths(PathSelectors.any()).build();
    }

    @Bean
    public Docket createRaApi(){
        return new Docket(DocumentationType.SWAGGER_2).groupName(ModelEnum.RA.getGroupName()).apiInfo(apiInfo())
                .select()
                .apis(Predicates.or(
                        RequestHandlerSelectors.basePackage(ModelEnum.RA.getPackagePath())
                ))
                .paths(PathSelectors.any()).build();
    }

    @Bean
    public Docket createTbApi(){
        return new Docket(DocumentationType.SWAGGER_2).groupName(ModelEnum.TB.getGroupName()).apiInfo(apiInfo())
                .select()
                .apis(Predicates.or(
                        RequestHandlerSelectors.basePackage(ModelEnum.TB.getPackagePath())
                ))
                .paths(PathSelectors.any()).build();
    }


    @Bean
    public Docket createTransferApi(){
        return new Docket(DocumentationType.SWAGGER_2).groupName(ModelEnum.TRANSFER.getGroupName()).apiInfo(apiInfo())
                .select()
                .apis(Predicates.or(
                        RequestHandlerSelectors.basePackage(ModelEnum.TRANSFER.getPackagePath())
                ))
                .paths(PathSelectors.any()).build();
    }

    @Bean
    public Docket createZZDApi(){
        return new Docket(DocumentationType.SWAGGER_2).groupName(ModelEnum.ZZD.getGroupName()).apiInfo(apiInfo())
                .select()
                .apis(Predicates.or(
                        RequestHandlerSelectors.basePackage(ModelEnum.ZZD.getPackagePath())
                ))
                .paths(PathSelectors.any()).build();
    }

    @Bean
    public Docket createOrApi(){
        return new Docket(DocumentationType.SWAGGER_2).groupName(ModelEnum.OR.getGroupName()).apiInfo(apiInfo())
                .select()
                .apis(Predicates.or(
                        RequestHandlerSelectors.basePackage(ModelEnum.OR.getPackagePath())
                ))
                .paths(PathSelectors.any()).build();
    }

    @Bean
    public Docket createDgApi(){
        return new Docket(DocumentationType.SWAGGER_2).groupName(ModelEnum.DG.getGroupName()).apiInfo(apiInfo())
                .select()
                .apis(Predicates.or(
                        RequestHandlerSelectors.basePackage(ModelEnum.DG.getPackagePath())
                ))
                .paths(PathSelectors.any()).build();
    }

    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("国资委 API Doc")
                .description("This is a restful api document of gzw.")
                .version("1.0")
                .build();
    }
}
